# -*- coding: utf-8 -*-

from WSModule import WSModule
from WSThread import WSThread
from WSJob import WSJob
from WSCounter import WSCounter
from WSResult import WSResult
from WSOption import WSOption

from HostsBruteResult import HostsBruteResult
from HostsBruteJob import HostsBruteJob
from HostsBruteThread import HostsBruteThread

import requests, os, time
# TODO брут без доменного имени
# TODO в лог опции брута

class HostsBrute(WSModule):
	log_path = os.getcwd() + '/results/HostsBrute-result'
	options = {"threads": WSOption("threads", "count thread", 5, False, ['-t', '--threads']),
			   "ip": WSOption("ip", "target ip", "62.148.228.5", True, ['-i', '--ip']),
			   "domain": WSOption("domain", "target domain", "vega-int.ru", True, ['-d', '--domain']),
			   "dict": WSOption("dict", "dictionary", "/tmp/2.txt", True, ['-f', '--file']), # TODO если директория, берём всё её содержимое рекурсивно - может класс под это?
			   "expr": WSOption("expr", "expression for false result", "", True, ['-e', '--expr'])}
	
	def run(self):
		self.result = HostsBruteResult()
		
		job = HostsBruteJob()
		job.load_file(self.options['dict'].value)
		
		counter = WSCounter(5, 150);
		
		workers = []
		for i in range(self.options['threads'].value):
			workers.append(HostsBruteThread(job, self.result, self.options['ip'].value,
															  self.options['domain'].value,
															  self.options['expr'].value,
															  counter))
		self.kernel.createThreads(workers)
		
	def help(self):
		return "Hosts brute module version 1.0"
	def finished(self):
		return self.kernel.finished()
		
